<?php
/**
 * BaseAjaxController
 *
 * @author
 * @version
 */
require_once 'DefaultController.php';
require_once 'configs/Config.php';
class BaseAjaxController extends DefaultController {

	var $_self_render = false;
	
	public function init() {
		parent::purify ();
		$this->rootDir = DirConfig::$root;
		//change the ErrorHandler plugin's error controller,
		//so that we can control the exceptions
		$plugin = $this->getFrontController ()->getPlugin ( 'Zend_Controller_Plugin_ErrorHandler' );
		if ($plugin != null) {
			$plugin->setErrorHandler ( array ('controller' => 'ajax-error', 'action' => 'error' ) );
		}
	}
	/**
	 * Don't need, so don't use
	 * (non-PHPdoc)
	 * @see application/controllers/BaseController::setupUserBar()
	 */
	public function setupUserBar() {
	}
	/**
	 * Encode the response before sending to client
	 * also disable the layout and view auto-rendering
	 * (non-PHPdoc)
	 * @see application/controllers/BaseController::postDispatch()
	 */
	public function postDispatch() {
		if (! $this->_self_render) {
			echo $this->_helper->renderAjaxResponse ();
		}
	}
	public function createErrorResult($errorMsg) {
		return array ('result' => 'error', 'message' => $errorMsg );
	}
}